export{}


// 函数

// 利用接口和类型别名为函数定义类型

//接口定义函数类型
interface SearchFunc {
    (source: string, subString: string): boolean;
}

let mySearch: SearchFunc;
mySearch = function(source: string, subString: string) {
    let result = source.search(subString);
    return result > -1;
}


//类型别名定义函数类型
type CreateAddFunc = (x: number, y: number) => number;

let createAdd: CreateAddFunc;
createAdd = function(x: number, y: number): number {
    return x + y; 
}

createAdd(1, 2)


//函数作为对象的属性出现的时候

interface ObjItf{
    fn:SearchFunc
}

let obj:ObjItf;
obj = {
    fn: function(source: string, subString: string) {
        let result = source.search(subString);
        return result > -1;
    }
}

obj.fn("123", "123")